Skip to content

feat(pool): add age-based transport expiration property - #34

Merged
bbottema merged 3 commits into
simple-java-mail:masterfrom
Gerrit23:feat/age-based-transport-expiration
Sep 17, 2026
Merged

bbottema merged 3 commits into
simple-java-mail:masterfrom
Gerrit23:feat/age-based-transport-expiration

Conversation

@Gerrit23

@Gerrit23 Gerrit23 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #33.

Add mail.smtppool.pool.expiration-since-creation-millis to the Jakarta Mail provider and document its use through Camel. The default 0 disables age-based expiration and preserves the existing single last-claim policy; negative values are rejected when the pool manager is created.

Update clustered-object-pool to 4.1.1, which brings in generic-object-pool 2.5.1. The provider uses the upstream CombinedExpirationPolicies to combine last-claim and creation-age thresholds. Distinct rules with identical thresholds remain present and retain separate expiry state, following Generic Object Pool #24 and #25.

Expiration is checked asynchronously while a transport is available. Active leases are not interrupted, and rapid reuse can delay retirement beyond the threshold; this is an eligibility setting rather than a hard connection-lifetime guarantee.

Validation: all 98 tests pass in the full JDK 21 mvn clean verify, including SpotBugs, executable demos, JPMS and binary compatibility checks. All 87 core/provider tests also pass on JDK 8. The deterministic equal-threshold regression fails with the old dependency and passes with the published update. Both object-pool JARs match Maven Central checksums.

Released in SMTP Connection Pool 4.2.0. Existing APIs, Java baselines and module names are preserved.

…mail#33)

Only idle-based expiration was selectable. A transport that is claimed
often enough never becomes idle long enough for
TimeoutSinceLastAllocationExpirationPolicy to retire it, so a pool cannot
respect a server that caps how long a connection may live regardless of
activity. Exchange Online, for example, resets an SMTP connection after
20 minutes even in the middle of a send.

Add mail.smtppool.pool.expiration-since-creation-millis. A transport now
expires when either the idle rule or the age rule matches. The default of
0 disables the age rule and preserves the existing behaviour exactly.

CombinedExpirationPolicies is deliberately not used to combine the two
rules. It holds its members in a Set, while TimeoutExpirationPolicy
derives equality from expiryAgeMs alone and its subclasses add no equality
of their own, so an idle threshold and an age threshold configured to the
same number of milliseconds compare equal and one rule is silently dropped.
A small private policy combines the two instead. Reported separately as
bbottema/generic-object-pool#24.
…il#33) [skip ci]

Add the new property to the provider configuration reference, and show in
the Camel adapter README how to set it from a smtppool:// URI, since mail.*
endpoint options already reach the Session.
@bbottema bbottema added enhancement dependencies Pull requests that update a dependency file labels Sep 17, 2026
@bbottema bbottema added this to the 4.2.0 milestone Sep 17, 2026
@bbottema
bbottema merged commit 2d0901d into simple-java-mail:master Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement

Development

Successfully merging this pull request may close these issues.

Allow age-based transport expiration, not only idle-based

2 participants